<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%	
	//获取项目名
	String path = request.getContextPath();
	//获取tomcat 协议+地址+端口号+ 获取项目名
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	//out.println(basePath);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>网站后台管理模版</title>
<link rel="stylesheet" type="text/css"
	href="<%=basePath %>background/static/admin/layui/css/layui.css" />
<link rel="stylesheet" type="text/css"
	href="<%=basePath %>background/static/admin/css/admin.css" />
<script src="<%=basePath %>jquery-3.5.1.js"></script>
<script
	src="<%=basePath %>bootstrap/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
<link rel="stylesheet"
	href="<%=basePath %>bootstrap/bootstrap-3.3.7-dist/css/bootstrap.css">
<link rel="stylesheet"
	href="<%=basePath %>background/ordUserJs/css/modifyRs.css">
<link rel="stylesheet" href="../css/sweetalert.css">
<script src="../js/sweetalert-dev.js"></script>
</head>
<body>

	<div class="wrap-container">
		<form class="layui-form" style="width: 90%; padding-top: 20px;">
			<div class="layui-form-item">
				<label class="layui-form-label">类别：</label>
				<div class="layui-input-block">
					<select id="kind" name="category" lay-verify="required">
						<option id="modify-op" value=""></option>
						<option value="0">HTML模板</option>
						<option value="1">CSS特效</option>
						<option value="2">jQuery代码</option>
					</select>
				</div>

			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">修改资源名称：</label>
				<div class="layui-input-block">
					<!-- placeholder="${ModifyRs.rsName}" -->
					<input value="" id="name" type="text" name="title"
						autocomplete="off" class="layui-input">
				</div>

			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">上传资源：</label>
				<div class="layui-input-block">
					<!-- required lay-verify="required" -->
					<input type="file" name="title" autocomplete="off"
						class="layui-input">
				</div>

			</div>
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">修改资源描述</label>
				<div class="layui-input-block">
					<textarea id="desc" name="desc" placeholder=""
						class="layui-textarea"></textarea>
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<!--lay-submit lay-filter="formDemo"  -->
					<button id="sub" class="layui-btn layui-btn-normal">修改</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>
	<%
		String rsId =  request.getParameter("rsId");
		String rsCategory =  request.getParameter("rsCategory");
		String rsName =  request.getParameter("rsName");
		String rsDes =  request.getParameter("rsDes");
		
		%>

	<script type="text/javascript" charset="utf-8">
			var rsId = <%=rsId%>;
			var rsCategory = <%=rsCategory%>;
			var rsName = <%=rsName%>
			var rsDes = <%=rsDes%>
			console.log(rsCategory);
			
			$(function(){
				
				if(rsCategory=='HTML模板'){
					document.getElementById("kind").value = "0";
				}else if(rsName=='CSS特效'){
					document.getElementById("kind").value = "1";
				}else if(rsDes =='jQuery代码'){
					document.getElementById("kind").value = "2";
				}
				
				document.getElementById("name").value = rsName;
				document.getElementById("desc").value = rsDes;
			}); 
		
			$("#sub").click(function(){
				
				var kind_temp = $("#kind").val();
				var rsCategory = null;
				if("0"==kind_temp){
					var rsCategory = "HTML模板";
				}else if("1"==kind_temp){
					var rsCategory = "CSS特效";
				}else if("2"==kind_temp){
					var rsCategory = "jQuery代码";
				}
				var rsName = $("#name").val();
				var rsDes = $("#desc").val();
				console.log(rsId,kind_temp,rsCategory,rsName,rsDes);
				
				if(rsCategory==null || rsCategory==""){
					swal("请选择资源的类别！");
					return;
				}
				if(rsName==null || rsName==""){
					swal("资源名称不能为空！");
					return;
				}
				if(rsDes==null || rsDes==""){
					swal("请对资源进行描述！");
					return;
				}
				
				$.ajax({
					url:"<%=basePath %>backgroundServlet",
					type:"get",
					data:"mark=modifyRs&rsId="+rsId+"&rsCategory="+rsCategory+"&rsName="+rsName+"&rsDes="+rsDes,
					dataType:"json",
					success:function(mes){
						console.log(mes);
						if(mes==true){
							alert("修改成功！");
							window.location.href = "<%=basePath %>backgroundServlet?mark=bShowRs&userId=${user.userId}&manage=${user.manage}";
							
						}else{
							alert("修改失败！");
							return;
						}
					}
				});
				
			});	
		</script>

	<%-- <script type="text/javascript" charset="utf-8">
			
			$(function(){
				if(${ModifyRs.rsCategory=='HTML模板'}){
					document.getElementById("kind").value = "0";
				}else if(${ModifyRs.rsCategory=='CSS特效'}){
					document.getElementById("kind").value = "1";
				}else if(${ModifyRs.rsCategory=='jQuery代码'}){
					document.getElementById("kind").value = "2";
				}
				
			}); 
		
			$("#sub").click(function(){
				var rsId = ${ModifyRs.rsId};
				var kind_temp = $("#kind").val();
				var rsCategory = null;
				if("0"==kind_temp){
					var rsCategory = "HTML模板";
				}else if("1"==kind_temp){
					var rsCategory = "CSS特效";
				}else if("2"==kind_temp){
					var rsCategory = "jQuery代码";
				}
				var rsName = $("#name").val();
				var rsDes = $("#desc").val();
				console.log(rsId,kind_temp,rsCategory,rsName,rsDes);
				$.ajax({
					url:"<%=basePath %>backgroundServlet",
					type:"get",
					data:"mark=modifyRs&rsId="+rsId+"&rsCategory="+rsCategory+"&rsName="+rsName+"&rsDes="+rsDes,
					dataType:"json",
					success:function(mes){
						if(mes==false){
							alert("修改失败！");
							return;
						}else{
							alert("修改成功！");
							window.location.href = "<%=basePath %>backgroundServlet?mark=bShowRs&userId=${user.userId}";
						}
					}
				});
				
			});	
		</script> --%>
	<script src="<%=basePath %>background/static/admin/layui/layui.js"
		type="text/javascript" charset="utf-8"></script>


	<script>
			//Demo
			layui.use(['form'], function() {
				var form = layui.form();
				form.render();
				//监听提交
				form.on('submit(formDemo)', function(data) {
					layer.msg(JSON.stringify(data.field));
					return false;
				});
			})
		</script>




</body>

</html>